<template>
    <div id="admin">
        <div :style="{left:asideLeft}" id="aside">
            <div id="aside-title">
                智慧超市运营管理系统
            </div>
            <div id="aside-wrap">
                <el-aside>
                    <el-menu
                            router
                            default-active="/admin"
                            :unique-opened="true"
                            background-color="#304156"
                            text-color="#fff"
                            active-text-color="#1890FF">
                        <el-menu-item index="/admin" @click="addTag('admin')">
                            <i class="el-icon-menu"></i>
                            <span slot="title">首页</span>
                        </el-menu-item>
                        <el-submenu index="2" class="aside-menu-item">
                            <template slot="title">
                                <i class="el-icon-goods"></i>
                                <span class="aside-menu-text">运营管理</span>
                            </template>
                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="purchase">采购管理</el-menu-item>
                                <el-menu-item class="menu-item" index="product">产品管理</el-menu-item>
                                <el-menu-item class="menu-item" index="finance">财务管理</el-menu-item>

                            </div class="menu-item">
                        </el-submenu>
                        <el-submenu index="3" class="aside-menu-item">
                            <template slot="title"><i class="el-icon-user"></i>
                                <span class="aside-menu-text">部门管理</span>
                            </template>
                            <div class="menu-item">
                                <el-menu-item index="department" class="menu-item">部门管理</el-menu-item>
                                <el-menu-item index="hr" class="menu-item">人事管理</el-menu-item>
                                <el-menu-item index="member" class="menu-item">员工管理</el-menu-item>
                            </div class="menu-item">
                        </el-submenu>
                        <el-submenu index="4" class="aside-menu-item">
                            <template slot="title"><i class="el-icon-data-line"></i>
                                <span class="aside-menu-text">数据分析</span>
                            </template>
                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="demand">需求分析</el-menu-item>
                            </div>

                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="psychology">心理分析</el-menu-item>
                            </div>

                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="location">区位分析</el-menu-item>
                            </div>

                        </el-submenu>
                        <el-submenu index="5" class="aside-menu-item">
                            <template slot="title"><i class="el-icon-s-check"></i>
                                <span class="aside-menu-text">系统工具</span>
                            </template>
                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="notice">通知公告</el-menu-item>
                            </div>
                            <div class="menu-item">
                                <el-menu-item class="menu-item" index="opinion">意见反馈</el-menu-item>
                            </div>
                        </el-submenu>
                    </el-menu>
                </el-aside>
            </div>
        </div>
        <div :style="{left:headerLeft}" id="header">
            <el-row>
                <el-col :span="1">
                    <div class="icon-click" @click="toggleAside">
                        <i class="el-icon-s-fold" v-show="showAside"></i>
                        <i class="el-icon-s-unfold" v-show="!showAside"></i>
                    </div>
                </el-col>
                <el-col :span="10" :offset="13">
                    <div class="header-right" style="margin-right: 20px;cursor: pointer;">
                        <span>

                        </span>
                        <span><i class="el-icon-s-custom"></i> {{username}}</span>
                        <span class="logout" @click="logout"></i>注销</span>
                    </div>

                    <div style="clear: right;"></div>
                </el-col>
            </el-row>
            <!-- <div class="tag-bar">
                 <el-tag hit size="small" effect="plain" @click="$router.push('/admin')">
                     首页
                 </el-tag>

                 <el-tag
                         :key="tag"
                         v-for="tag in dynamicTags"
                         closable
                         hit
                         size="small"
                         :disable-transitions="false"
                         effect="plain"
                         @click="handleTagClick(tag)"
                         @close="handleClose(tag)">
                     {{tag}}
                </el-tag>
            </div>-->
        </div>
        <div :style="{left:headerLeft}" id="main">
            <router-view></router-view>
        </div>
    </div>
</template>

<script>
    export default {
        name: "Admin",
        mounted() {
            this.username = sessionStorage.getItem("username");
        },
        data() {
            return {
                asideLeft: "0",
                headerLeft: "200px",
                showAside: true,
                dynamicTags: [],
                username: '未知的人'
            }
        },
        methods: {
            toggleAside() {
                if (this.showAside) {
                    this.asideLeft = "-200px";
                    this.headerLeft = "0";
                } else {
                    this.asideLeft = "0";
                    this.headerLeft = "200px";
                }
                this.showAside = !this.showAside;
            },
            handleTagClick(tag) {
                this.$router.push(tag);
            },
            handleClose(tag) {
                this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
            },
            addTag(title) {
                if (title === 'admin') {
                    return false;
                }
                if (this.dynamicTags.includes(title)) {
                    return false;
                }

                this.dynamicTags.push(title)
            },
            logout() {
                sessionStorage.clear();
                localStorage.clear();
                this.$router.push("/");
            }
        },
    }
</script>

<style scoped lang="scss">
    $width: 200px;
    $height: 50px;
    $transition-delay: 0.5s;
    #aside {
        transition: $transition-delay;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: $width;
        background-color: #304156;
        padding-top: $height;

        #aside-title {
            position: fixed;
            top: 0;
            width: $width;
            height: $height;
            color: #ffffff;
            text-align: center;
            line-height: 50px;
            font-size: 14px;
            /*background-color: #2b2f3a;*/
            background-color: #4ba1ed;
        }

        #aside-wrap {
            z-index: -10;
            position: fixed;
            top: $height;
            bottom: 0;
            width: $width;
            overflow-y: auto;
            overflow-x: hidden;

            &::-webkit-scrollbar {
                /*滚动条整体样式*/
                width: 2px; /*高宽分别对应横竖滚动条的尺寸*/
                height: 1px;
            }

            &::-webkit-scrollbar-thumb {
                /*滚动条里面小方块*/
                border-radius: 10px;
                background-color: skyblue;
                background-image: -webkit-linear-gradient(
                                45deg,
                                rgba(255, 255, 255, 0.2) 25%,
                                transparent 25%,
                                transparent 50%,
                                rgba(255, 255, 255, 0.2) 50%,
                                rgba(255, 255, 255, 0.2) 75%,
                                transparent 75%,
                                transparent
                );
            }

            &::-webkit-scrollbar-track {
                /*滚动条里面轨道*/
                box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
                background: #ededed;
                border-radius: 10px;
            }


            .aside-menu-text {
                color: #ffffff;
            }
        }

    }

    #header {
        box-shadow: 0 1px 3px darkgrey;
        z-index: 1;
        transition: $transition-delay;
        position: fixed;
        top: 0;
        right: 0;
        left: $width;
        height: $height;
        font-size: 22px;

        .icon-click {
            padding: 0 15px;
            height: $height;
            line-height: $height;
        }

        .el-breadcrumb {
            height: 100%;
            line-height: $height;
        }

        .header-right {
            height: 100%;
            float: right;
            line-height: $height;
            font-size: 13px;
            padding-right: 15px;

            .logout {
                color: #466cff;
                margin: 20px;
                cursor: pointer;

                &:hover {
                    color: #6384ff;;
                }
            }
        }

        .tag-bar {
            background-color: #ffffff;
            padding-left: 12px;
            border-top: 1px solid #d2d2d2;
        }
    }

    #main {
        transition: $transition-delay;
        position: fixed;
        top: $height;
        bottom: 0;
        left: $width;
        right: 0;
        overflow: auto;
        padding: 8px;
    }

    .menu-item {
        background-color: #1f2d3d !important;

        &:hover {
            background-color: #19233d !important;
        }
    }


    .el-menu {
        border-right-width: 0;
        background-color: #304156;

    }

    .el-aside {
        width: 100% !important;
        background-color: #304156;
        overflow: hidden;
    }

    .el-tag {
        margin: 0 5px;
        cursor: pointer;
        border-radius: 0;
        user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        -webkit-user-select: none;
    }

    .el-menu-item-group__title {
        padding: 0 !important;
    }
</style>